<!DOCTYPE html>
<html lang="zh-Hans">
<head>
    <title>产前诊断系统登录</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chorme=1">
    <meta name="renderer" content="webkit">
    <link rel="shortcut icon" href="img/favicon.ico">
    <link rel="Bookmark" href="img/favicon.ico"/>
    <!--[if lt IE 10]>
    <script>location.href='/static/html/unsupported.html'</script>
    <![endif]-->
    <script src="/static/common/js/sm3.js" type="text/javascript"></script>
    <style type="text/css">
        *, *::before, *::after{
            box-sizing: border-box;
        }
        html,body{
            font-weight: 300;
            font-family: "Arial", "Microsoft YaHei", "微软雅黑", SimSun, 宋体,serif;
        }
        body{
            display: flex;
            flex-direction: column;
            color: #646c9a;
            line-height: 1.5;
            margin: 0;
            height: 100vh;
            background-image: url("/static/cqzd/assets/login/bg.jpg");
            background-size:100% 100%;
        }

        .sp-grid{
            flex: 1;
        }
        .sp-grid--ver{
            display: flex;
            flex-direction: row;
        }
        .sp-grid--hor{
            display: flex;
            flex-direction: column;
        }

        .sp-grid-full{
            width: 100%;
            height: 100vh;
        }

        .sp-grid-vh-center{
            display: flex;
            align-items: center;
            justify-content:center;
        }
        .btn{
            border: none;
            transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
            text-decoration: none;
            border-radius: 0.25rem;
            flex: 0 1 auto;
            overflow: hidden;
            display: flex;
            position: relative;
            justify-content:center;
            align-items:center;
            box-shadow: 0 .25rem 1rem 0 rgba(93, 120, 255, 0.15);
        }

        .btn:hover{
            box-shadow: 0 .25rem 1rem 0 rgba(93, 120, 255, 0.25)
        }

        .btn.btn--primary:active{
            background-color: #0a82ff;
        }
        .btn.btn--primary{
            color: #fff;
            background-color: #1cc5ff;
        }


        .btn .btn-hover-effect {
            z-index: 5;
            content: "";
            position: absolute;
            left: 0;
            top: 0;
            width: 0;
            height: 0;
            background: radial-gradient(circle closest-side, #4becff, transparent);
            transform: translate(-50%, -50%);
            transition: width .2s ease, height .2s ease;
        }

        .btn .btn__icon, .btn .btn__text {
            z-index: 10;
            position: relative;
            pointer-events: none
        }

        .btn:hover .btn-hover-effect {
            width: 18.75rem;
            height: 18.75rem;
        }

        .btn:active .btn-hover-effect {
            width: 37.5rem;
            height: 37.5rem;
        }

        .btn--light-overlay .btn-hover-effect {
            opacity: .1
        }

        .btn--light-overlay:hover .btn-hover-effect {
            width: 12.5rem;
            height: 12.5rem;
        }

        .btn--light-overlay:active .btn-hover-effect {
            width: 37.5rem;
            height: 37.5rem;
        }

        .login-section{
            width: 71.5rem;
            height: 37.3125rem;
            background-color: #ffffff;
            box-shadow: 0 .3125rem 1.8125rem 0 rgba(0, 0, 0, 0.2);
        }
        .login-section-aside{
            align-items: center;
            display: flex;
            width: 30.625rem;
            height: 37.375rem;
            background-image: url("/static/cqzd/assets/login/login-bg.png");
            background-size: 100% 100%;
        }
        .login-section-aside::after{
            content: '';
            width: 10.0625rem;
            height: 13.1875rem;
            background-image: url("/static/cqzd/assets/login/login-icon.png");
            background-size: 100% 100%;
        }
        .login-section-title{
            width: 42.0625rem;
            height: 6rem;
            background-color: #1cc5ff;
            align-items: center;
            display: flex;
        }

        .login-section-title img{
            font-size: 1.875rem;
            font-weight: normal;
            font-stretch: normal;
            letter-spacing: 0;
            color: #ffffff;
            margin: 0;
            padding:0 .75rem 0 1.875rem;
            display: inline-block;
            height: 50px;
        }

        .login-section-content{
            padding: 1.875rem;
        }
        .login-section-input .form-group{
            display: flex;
            height: 5rem;
            background-color: #fff;
            border-radius: .3125rem;
            border: solid .0625rem #eee;
            transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
        }

        .login-section-input .form-group:not(:first-child){
            margin-top: 1.25rem;
        }

        .login-section-input .input-group-prepend{
            display: flex;
            align-items: center;
            width: 4.125rem;
            justify-content: flex-end;
        }
        .login-section-input .input-group-prepend img{
            display: flex;
            width: 2rem;
            height: 2.125rem;
        }

        .login-section-input .form-control{
            display: block;
            width: 100%;
            padding: 0.65rem 1.6rem;
            color: #afadb0;
            font-size: 2rem;
            font-weight: 400;
            line-height: 1.5;
            background-color: #fff;
            background-clip: padding-box;
            border: none;
        }

        input::-webkit-input-placeholder, textarea::-webkit-input-placeholder {
            color: #afadb0;
            font-size: 1.5rem;
        }
        input::-moz-placeholder, textarea::-moz-placeholder {
            color: #afadb0;
            font-size: 1.5rem;
        }
        input:-ms-input-placeholder, textarea:-ms-input-placeholder {
            color: #afadb0;
            font-size: 1.5rem;
        }

        .captcha-input-group{
            justify-content: flex-start;
        }
        .captcha-input-group .login-section-captcha{
            height: 5rem;
            width: 11.25rem;
            margin-top: 1.25rem;
            background-color: #ffffff;
            border-radius: .3125rem;
            border: solid .0625rem #eee;
            margin-right: 1.75rem;
            overflow: hidden;
        }

        .captcha-input-group .login-section-captcha img{
            width: 100%;
            height: 100%;
            cursor: pointer;
        }

        .captcha-input-group .form-group{
            width: 12.5rem;
        }
        .login-section-action{
            margin-top: 2.625rem;
            text-align: center;
        }
        .login-section-btn{
            display: inline-block;
            width: 28.625rem;
            height: 4.875rem;
            line-height: 4.875rem;
            border-radius: 4.875rem;
            font-size: 1.875rem;
        }
        .login-section-btn svg{
            width: 3rem;
            height: 4.75rem;
            display: none;
            z-index: 10;
            animation: rotate 2s linear infinite;
        }

        @keyframes rotate{from{transform: rotate(0deg)}
            to{transform: rotate(359deg)}
        }
    </style>
</head>
<!-- begin::Body -->
<body class="">
<!-- begin:: Page -->
<div class="sp-grid sp-grid--ver sp-grid--root">
    <div class="sp-grid sp-grid--hor sp-grid--root sp-grid-full sp-grid-vh-center">
        <div class="login-section sp-grid--ver">
            <div class="login-section-aside sp-grid-vh-center"></div>
            <div class="login-section-input">
                <div class="login-section-title">
                    <img src="/static/cqzd/img/sysname.png"/>
                </div>
                <div class="login-section-content sp-grid--hor">
                    <form method="post" action="/security/sign/lookup">
                        <div class="form-group">
                            <div class="input-group-prepend">
                                <img src="/static/cqzd/assets/login/login-input-user.png">
                            </div>
                            <input class="form-control" type="text" placeholder="用户名" name="username" value="" autocomplete="off">
                        </div>
                        <div class="form-group">
                            <div class="input-group-prepend">
                                <img src="/static/cqzd/assets/login/login-input-pw.png">
                            </div>
                            <input class="form-control" type="password" placeholder="密码" name="password" value="" autocomplete="current-password">
                        </div>
                        <div class="captcha-input-group sp-grid-vh-center">
                            <div class="login-section-captcha">
                                <img src="/security/captcha" id="captcha" alt="验证码" title="点击更换验证码"
                                     onclick="this.src = '/security/captcha?_t='+new Date().getTime();">
                            </div>
                            <div class="form-group">
                                <input class="form-control" type="text" placeholder="验证码" maxlength="4" name="captcha" autocomplete="off" onkeyup="if(event.keyCode===13){document.querySelector('.login-section-btn').click()}">
                            </div>
                        </div>
                        <div class="login-section-action">
                            <button type="submit" class="btn btn--primary login-section-btn">
                                <span class="btn__text">登录</span>
                                <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1">
                                    <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                                        <g id="Group">
                                            <polygon id="Shape" points="0 0 24 0 24 24 0 24"/>
                                        </g>
                                        <path d="M12,4 L12,6 C8.6862915,6 6,8.6862915 6,12 C6,15.3137085 8.6862915,18 12,18 C15.3137085,18 18,15.3137085 18,12 C18,10.9603196 17.7360885,9.96126435 17.2402578,9.07513926 L18.9856052,8.09853149 C19.6473536,9.28117708 20,10.6161442 20,12 C20,16.418278 16.418278,20 12,20 C7.581722,20 4,16.418278 4,12 C4,7.581722 7.581722,4 12,4 Z" id="Oval-3"
                                              fill="#fff" fill-rule="nonzero" opacity="1" transform="translate(12.000000, 12.000000) scale(-1, 1) translate(-12.000000, -12.000000) "/>
                                    </g>
                                </svg>
                            </button>
                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>
</div>
<script type="application/javascript">

    window.onload = function () {

        function onError(evt) {
            console.log(evt);
            progressBtn(btn,true);
        }

        var form = document.querySelector("form");
        var usernameInput = document.getElementsByName('username')[0];
        var pwInput = document.getElementsByName('password')[0];
        var captchaInput = document.getElementsByName('captcha')[0];
        var btn = document.querySelector('.login-section-btn');
        //login
        var loginXhr = new XMLHttpRequest();
        loginXhr.onload = function (evt) {
            if (evt.target.status === 200 && evt.target.responseText) {
                var msg = JSON.parse(evt.target.responseText)||{};
                if(msg.status===1){
                    try {
                        sessionStorage.setItem('userName',msg.userName);
                        sessionStorage.setItem('userOrg',msg.userOrg);
                        sessionStorage.setItem('userRole',msg.userRole);
                    }catch (ignore) {}
                    //login success
                    top.location.href = msg.page;
                    return;
                }
                progressBtn(btn,true);
                alert(msg.message||'Incorrect username or password. Please try again.');
                //change captcha
                var ccEvt = document.createEvent("HTMLEvents");
                ccEvt.initEvent("click", false, true);
                document.getElementById('captcha').dispatchEvent(ccEvt);
            }else{
                onError();
            }
        };
        loginXhr.onerror = onError;

        //lookup
        var lookupXhr = new XMLHttpRequest();
        lookupXhr.onload = function (evt) {
            if (evt.target.status === 200 && evt.target.responseText) {
                var responseText = JSON.parse(evt.target.responseText);
                var salt = responseText.salt;
                var password = pwInput.value;
                //
                var formData = new FormData();
                formData.append("username",usernameInput.value);
                formData.append("password", digestSM3(password,salt));
                formData.append("captcha", captchaInput.value);
                //

                loginXhr.open('POST', '/security/sign/in', true);
                loginXhr.setRequestHeader("x-requested-with","XMLHttpRequest");
                loginXhr.send(formData);
            }else{
                onError();
            }
        };
        lookupXhr.onerror = onError;

        var  digestSM3 = function (text,salt) {
            text = sm3_digest(text);
            text = "xc9vjr3.243"+salt+text.substring(8,60)+"*2`34gh59";
            return  sm3_digest(text);
        };

        var progressBtn = function(btn,enable){
            if(enable){
                btn.querySelector(".btn__text").style.display = 'inline-block';
                btn.querySelector("svg").style.display = 'none';
                btn.disabled = false;
            }else{
                btn.querySelector(".btn__text").style.display = 'none';
                btn.querySelector("svg").style.display = 'inline-block';
                btn.disabled = true;
            }
        };

        //bind submit event
        form.addEventListener('submit', function(ev) {
            ev.preventDefault();

            if(!usernameInput.value){
                usernameInput.placeholder = "请输入用户名";
                usernameInput.focus();
                return;
            }
            if(!pwInput.value){
                pwInput.placeholder = "请输入密码";
                pwInput.focus();
                return;
            }
            if(!captchaInput.value){
                captchaInput.placeholder = "请输入验证码";
                captchaInput.focus();
                return;
            }

            var formData = new FormData();
            formData.append("username", usernameInput.value);
            //
            lookupXhr.open('POST', '/security/sign/lookup', true);
            lookupXhr.setRequestHeader("x-requested-with","XMLHttpRequest");
            lookupXhr.send(formData);
            progressBtn(btn);
        }, false);
    };

    (function () {
        var btns = [].slice.call(document.querySelectorAll(".btn--primary:not(.btn--outline):not(.btn--link):not(.no-hover-effect), .btn--light-overlay:not(.no-hover-effect)"));
        btns.forEach(function (e) {
            var t = document.createElement("span");
            t.className = "btn-hover-effect";
            var i = e.appendChild(t);
            e.onmousemove = function (e) {
                var t = e.currentTarget.getBoundingClientRect(), s = e.clientX - t.left, a = e.clientY - t.top;
                i.style.left = s + "px", i.style.top = a + "px"
            }
        });
        function computed() {
            var HTML = document.documentElement;
            var winW = HTML.clientWidth;
            winW = winW>2560 ? 2560 : winW;
            HTML.style.fontSize = ((winW / 1920) * 16)+'px';
            //console.log(winW+"--"+HTML.style.fontSize)
            //把改变后的根节点大小传出去，也可以存在 redux 中，比如 Echarts 就需要判断是否需要重绘
            //that.props.changeFontSize(HTML.style.fontSize)
        }
        computed();
        //window.onresize = computed;
        window.addEventListener('resize', computed, false);
    })();
</script>
<!-- end:: Page -->
</body>
</html>